package com.emellend.api.text;

import com.emellend.api.R;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.text.style.StyleSpan;
import android.text.style.URLSpan;
import android.widget.TextView;

public class Link extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.link);
		init();
	}

	private void init() {
		TextView text2=(TextView) this.findViewById(R.id.text2);
		text2.setMovementMethod(LinkMovementMethod.getInstance());
		
		//这种方式暗示着，其实可以从网络或者其他地方动态的添加链接
		TextView text3=(TextView) this.findViewById(R.id.text3);
		text3.setText(Html.fromHtml("<b>text3:</b>  Text with a " +
                "<a href=\"http://www.google.com\">link</a> " +
                "created in the Java source code using HTML."));
		text3.setMovementMethod(LinkMovementMethod.getInstance());
		
		SpannableString ss=new SpannableString("text4: Click here to dial the phone.");
		ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		ss.setSpan(new URLSpan("tel:4155551212"), 13, 17, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
		
		TextView text4=(TextView) this.findViewById(R.id.text4);
		text4.setText(ss);
		text4.setMovementMethod(LinkMovementMethod.getInstance());
		
	}
}
